package com.zhouyer.study.controller;

import com.zhouyer.study.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 验证码服务Controller
 *
 * @author zhouyao
 * @version 1.0
 * @date 2021/12/7 9:02 上午
 */
@RestController
@RequestMapping("/code")
public class CodeController {
    @Autowired
    private CodeService codeService;

    /**
     * 生成验证码，并存储到数据库，然后发送邮件
     *
     * @param email 邮箱地址
     * @return boolean
     * @author zhouyao
     */
    @GetMapping("/create/{email}")
    public Boolean createCode(@PathVariable("email") String email) {
        return codeService.createCode(email);
    }

    /**
     * 验证邮箱地址及验证码
     *
     * @param email 邮箱地址
     * @param code  验证码
     * @return java.lang.Integer
     */
    @GetMapping("/validate/{email}/{code}")
    public Integer validateCode(@PathVariable("email") String email, @PathVariable("code") String code) {
        return codeService.validateCode(email, code);
    }
}
